export default {
	searchCondition_() {
		return {
			categoryId: null,
			keyword: null,
			priceType: 'brent',
			types: [],
			arrivedPort: null,
			contractDate: null,
			address: null,
			province: null, //省份
			city: null, //城市
			latitude: null,
			longitude: null,
			params: [],
			qty: null,
			deviceFlag: false
		}
	},
	async placePortList() {
		let res = await this.httptool.post(this.apis.placePortList, null);

		this.$store.commit('changeValue', {
			name: 'placePortList',
			value: res.data
		})
		console.log(this.$store.state.placePortList)
	},
	async latestPrice() {
		let res = await this.httptool.post('betaBrtWtiExcRateAPI/getAll', null);
		this.latestPrices = res.data;

	},
	async productChildName() {
		let params = {
			categoryId: this.typeIds[0]
		}
		let res = await this.httptool.post(this.apis.productChildName, params);
		this.treeTwoDate = res.data;
		this.setCurrentTwoItem();
		this.compare();
	},
	async productParam() {
		if(this.currentType.id != 6 && this.currentType.id != 7) {
			return;
		}
		let params = {
			categoryId: this.currentType.id
		}
		let res = await this.httptool.post(this.apis.productParam, params);
		let data = res.data;
		if(data.length > 0) {
			let arr = data.map(item => {
				return {
					param: item,
					start: null,
					end: null
				}
			})
			this.searchCondition.params = arr;
		} else {
			this.searchCondition.params = [];
		}
		this.productSearch()
	},
	async productSearch() {
		
		
		if(this.pageNum != 1 && this.total && this.list.length >= this.total) {
			return;
		}
		this.searchCondition.categoryId = this.currentType.id;
		console.log(this.searchCondition)
		if(this.currentType.id != 6 & this.currentType.id != 7) {
			this.searchCondition.priceType = null;
		}
		this.searchCondition.pageNum = this.pageNum;
		this.searchCondition.pageSize = 4;
		let res = await this.httptool.post(this.apis.productSearch, this.searchCondition);
		if(res) {
			if(this.pageNum == 1) {
				this.list = res.data.list;
			} else {
				this.list = this.list.concat(res.data.list);
			}
			this.total = res.data.total;
			this.pageNum++;
			this.listPage = new Array(this.list.length).fill(1);
			this.jumpPage = new Array(this.list.length).fill(1);

		}

	},
	async productNextSearch(page, item, index) {
		let params = {
			pageNum: page,
			pageSize: 3,
			name: item.group,
			categoryId: item.products[0].categoryId,
			deviceFlag: this.searchCondition.deviceFlag,
			contractDate: this.searchCondition.contractDate,
			priceType: this.searchCondition.priceType,
			qty: this.searchCondition.qty,
			latitude: this.searchCondition.latitude,
			longitude: this.searchCondition.longitude
		}
		let res = await this.httptool.post(this.apis.productSearch, params);
		let data = res.data;
		this.list[index].products = data.list;
		this.listPage.splice(index, 1, page);
	},
	setCurrentTwoItem() {
		let id = this.currentType.id;
		if(this.treeTwoDate && this.treeTwoDate.length > 0) {
			for(let item of this.treeTwoDate) {
				if(item.id == id) {
					this.currentTwoItem = item;
					return;
				}
			}
		}
	},
	setCategoryId() {
		if(this.treeTwoDate.length == 2 && this.treeTwoDate[0].children.length > 0) {
			if(this.currentTwoItem) {
				this.searchCondition.categoryId = this.currentTwoItem.id;
			}
		} else {
			this.searchCondition.categoryId = this.currentItem.id;
		}

	},
	canView(id) {
		//7国际贸易，6国内现货  8成品油 9半成品油  3化工品 4LNG 5化工品
		//计价方式、数量、油种
		if(id == 0) {
			let arr = [6, 7]
			if(arr.indexOf(this.currentType.id) > -1) {
				return true;
			}
		}
		//提货港口、合约月
		if(id == 1) {
			let arr = [7]
			if(arr.indexOf(this.currentType.id) > -1) {
				return true;
			}
		}
		//成品油
		if(id == 2) {
			let arr = [8]
			if(arr.indexOf(this.currentType.id) > -1) {
				return true;
			}
		}
		//半成品油
		if(id == 3) {
			let arr = [9]
			if(arr.indexOf(this.currentType.id) > -1) {
				return true;
			}
		}
		//成品油
		if(id == 4) {
			let arr = [3, 4, 5]
			if(arr.indexOf(this.currentType.id) > -1) {
				return true;
			}
		}
		//地址
		if(id == 5) {
			let arr = [8, 9, 3, 4, 5]
			if(arr.indexOf(this.currentType.id) > -1) {
				return true;
			}
		}
		//石油石化
		if(id == 6) {
			let arr = [8, 9, 3, 4]
			if(arr.indexOf(this.currentType.id) > -1) {
				return true;
			}
		}
		return false;
	},
	async productPrice() { //价格走势
		let arr = ['', '7', '30', '90']
		let params = {
			name: this.productName,
			time: arr[this.type]
		}
		let res = await this.httptool.post(this.apis.productPrice, params);
		let data = res.data;
		this.xAxis = data.price.dates;
		this.yAxis = data.price.prices;
		this.lowest = data.lowest;
		this.$nextTick(() => {
			this.drawLine();
		})
	}
}